import requests
import json
from spiders.utils import delete_all_topics


def get_topic_list():
    """
    抓取话题
    """
    delete_all_topics()

    topic_api = 'https://api.diary.biku8.com/diary/getTopicList.api?pageId=1&pageSize=15'
    r = requests.get(topic_api)
    res = json.loads(r.text)
    for topic in res['data']:
        post_body = {
            'topicName': topic['topicName'],
            'topicDesc': topic['topicDesc'],
            'diaryCount': 0,
            'clickNum': 0,
            'thumbImgUrl': topic['thumbImgUrl'],
            'imgUrl': topic['imgUrl']
        }
        r = requests.post('http://121.199.62.61/topics', data=post_body)
        if r.status_code == 200:
            print('新建成功: ' + topic['topicName'])

def get_banner_list():
    pass


def run():
    get_topic_list()
